<template>
  <v-data-table :headers="headers" 
  :items="desserts" 
  sort-by="calories" 
  class="elevation-1"
  calculate-widths>
    <template v-slot:top>
      <v-toolbar flat>
        <v-toolbar-title>主流水</v-toolbar-title>
        <v-divider class="mx-4" inset vertical></v-divider>
        <v-spacer></v-spacer>
        <v-dialog v-model="dialog" max-width="800px">
          <template v-slot:activator="{ on }">
            <v-btn color="primary" dark class="mb-2" v-on="on">新增主流水</v-btn>
          </template>
          <v-card>
            <v-card-title>
              <span class="headline">{{ formTitle }}</span>
            </v-card-title>

            <v-card-text>
              <v-container>
                <v-row>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.bankid" label="银行号"></v-text-field>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.trandate" label="记账会计日期"></v-text-field>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.accdate" label="会计核算日期"></v-text-field>
                  </v-col>
                   <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.accseqno" label="会计核算流水号"></v-text-field>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                     <v-select 
                     :items="brcItems" 
                     label="交易机构" 
                     v-model="editedItem.brctran"
                      item-text="brcname"
                      item-value="brc"
                     ></v-select>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.trancode" label="交易码"></v-text-field>
                  </v-col>
                 <v-col cols="12" sm="6" md="4">
                      <v-select 
                      :items="moduleItems" 
                      label="所属子系统" 
                      v-model="editedItem.subsys"
                      item-text="name"
                      item-value="attributes"
                     ></v-select>
                  </v-col>
                   <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.frntdate" label="发起方交易日期"></v-text-field>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.frntseq" label="发起方流水号"></v-text-field>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.oriaccdate" label="原会计核算日期"></v-text-field>
                  </v-col>
                   <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.oaccseqno" label="原会计核算流水号"></v-text-field>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.kltrndate" label="核心交易日期"></v-text-field>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.kltrnseq" label="核心流水号"></v-text-field>
                  </v-col>

                  

                   <v-col cols="12" sm="6" md="4">
                      <v-select 
                      :items="acdealflgItems" 
                      label="会计核算流水处理标识" 
                      v-model="editedItem.acdealflg"
                      item-text="name"
                      item-value="attributes"
                     ></v-select>
                  </v-col>


                  <v-col cols="12" sm="6" md="4">
                      <v-select 
                      :items="flgtimItems" 
                      label="定时/实时标志" 
                      v-model="editedItem.flgtim"
                      item-text="name"
                      item-value="attributes"
                     ></v-select>
                  </v-col>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.isclsal" label="是否允许冲销"></v-text-field>
                  </v-col>


                  <v-col cols="12" sm="6" md="4">
                      <v-select 
                      :items="jouracctypItems" 
                      label="交易流水类型" 
                      v-model="editedItem.jouracctyp"
                      item-text="name"
                      item-value="attributes"
                     ></v-select>
                  </v-col>
                 
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.flgcanl" label="被冲销标志"></v-text-field>
                  </v-col>
            
                   <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.telchk" label="复核柜员"></v-text-field>
                  </v-col>
                   <v-col cols="12" sm="6" md="4">
                  <v-select :items="rcdstsItems" 
                  label="记录状态" 
                  v-model="editedItem.stsrcd"
                  item-text="name"
                  item-value="attributes"
                  ></v-select>
                  </v-col>
                   
                </v-row>
              </v-container>
            </v-card-text>

            <v-card-actions>
              <v-spacer></v-spacer>
              <v-btn color="blue darken-1" text @click="close">取消</v-btn>
              <v-btn color="blue darken-1" text @click="save">保存</v-btn>
            </v-card-actions>
          </v-card>
        </v-dialog>
      </v-toolbar>
    </template>
    <template v-slot:item.actions="{ item }">
      <v-icon small class="mr-2" @click="editItem(item)">mdi-pencil</v-icon>
      <v-icon small @click="deleteItem(item)">mdi-delete</v-icon>
    </template>
    <template v-slot:no-data>
      <v-btn color="primary" @click="initialize">Reset</v-btn>
    </template>

       <template v-slot:item.stsrcd="{ item }">
    
      <span v-for="s in rcdstsItems" key="s.id" v-if="s.attributes==item.stsrcd">{{s.name}}</span>
    </template>
  </v-data-table>
</template>

<script>
export default {
  data: () => ({
    thisSerseqn:'',
    chnelnoItems:[],
    moduleItems:[],
    flgtimItems:[],
    rcdstsItems:[],
    acdealflgItems:[],
    jouracctypItems:[],
    dialog: false,
    brcItems:[],
    headers: [
      { text: "银行号", value: "bankid" },
      // { text: "记账会计日期", value: "trandate" },
      { text: "核算会计日期", value: "accdate" },
      { text: "会计核算流水号", value: "accseqno" },
      // { text: "交易机构", value: "brctran" },
      { text: "交易码", value: "trancode" },
      { text: "所属子系统", value: "subsys" },
      // { text: "发起方交易日期", value: "frntdate" },
      // { text: "发起方流水号", value: "frntseq" },
      // { text: "原会计核算日期", value: "oriaccdate" },
      // { text: "原会计核算流水号", value: "oaccseqno" },
      { text: "核心交易日期", value: "kltrndate" },
      { text: "核心流水号", value: "kltrnseq" },
      { text: "会计核算流水处理标识", value: "acdealflg" },
      // { text: "定时/实时标志", value: "flgtim" },
      // { text: "是否允许冲销", value: "isclsal" },
      // { text: "交易流水类型", value: "jouracctyp" },
      // { text: "被冲销标志", value: "flgcanl" },
     
      // {text: "复核柜员", value: "telchk" },
      {text: "记录状态", value: "stsrcd" },
      {text: "操作", value: "actions", sortable: false }
    ],
    desserts: [],
    editedIndex: -1,
    editedItem: {
      bankid: "",
      trandate:"",
      accdate:"",
      accseqno:"",
      brctran: "",
      trancode:"",
      subsys: "",
      frntdate: "",
      frntseq: "",

      oriaccdate: "",
      oaccseqno:"",
      kltrndate:"",
      kltrnseq:"",
      acdealflg: "0",
      flgtim:"",
      isclsal: "",
      jouracctyp: "0",
      flgcanl: "",

      comsrvflg: "",
      telchk:"",
      stsrcd:"1",
    },
    defaultItem: {
      bankid: "",
      trandate:"",
      accdate:"",
      accseqno:"",
      brctran: "",
      trancode:"",
      subsys: "",
      frntdate: "",
      frntseq: "",

      oriaccdate: "",
      oaccseqno:"",
      kltrndate:"",
      kltrnseq:"",
      acdealflg: "0",
      flgtim:"",
      isclsal: "",
      jouracctyp: "0",
      flgcanl: "",

      comsrvflg: "",
      telchk:"",
      stsrcd:"1",
    }
  }),

  computed: {
    formTitle() {
      return this.editedIndex === -1 ? "新增" : "修改";
    }
  },

  watch: {
    dialog(val) {
      val || this.close();
    }
  },

  created() {
    this.initialize();
    this.getDict();
  },

  methods: {
    initialize() {
     this.axios
        .get("/acfm15/list")
        .then(response => {
          this.desserts = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
    },
     getDict(){
        this.axios
        .get("/dict/topName/渠道")
        .then(response => {
          this.chnelnoItems = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
        this.axios
        .get("/dict/topName/交易模块")
        .then(response => {
          this.moduleItems = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
        this.axios
        .get("/dict/topName/定时实时标志")
        .then(response => {
          this.flgtimItems = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });

        this.axios
        .get("/brcInfo/list")
        .then(response => {
          this.brcItems = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
        this.axios
        .get("/dict/topName/记录状态")
        .then(response => {
          this.rcdstsItems = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
        this.axios
        .get("/dict/topName/会计流水处理标志")
        .then(response => {
          this.acdealflgItems = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
        this.axios
        .get("/dict/topName/交易流水类型")
        .then(response => {
          this.jouracctypItems = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
      
        
    },
    editItem(item) {
      this.editedIndex = this.desserts.indexOf(item);
      this.editedItem = Object.assign({}, item);
      this.dialog = true;
    },

    

    deleteItem(item) {
      const index = this.desserts.indexOf(item);
      confirm("确定要删除此条记录吗?") &&
        this.axios.delete('/acfm15/'+item.id)
          .then(res=>{
            this.desserts.splice(index, 1); 
          })
        
    },

    close() {
      this.dialog = false;
      this.$nextTick(() => {
        this.editedItem = Object.assign({}, this.defaultItem);
        this.editedIndex = -1;
      });
    },

    save() {
       this.axios.post("/acfm15", this.$qs.stringify(this.editedItem)).then(res => {
          this.initialize();
          this.close();
      });
      
    }
  }
};
</script>